package cn.qu.phizline.connect;

import org.webrtc.IceCandidate;
import org.webrtc.PeerConnection;
import org.webrtc.SessionDescription;

import java.util.List;

import cn.qu.phizline.AndroidPayloadConventer;
import cn.qu.phizline.event.login.LoginEvent;

public interface AppRTCClient {

    /**
     * 房间参数结构定义
     */
    class RoomConnectionParameters {
        public final String roomUrl;
        public final String roomId;

        public RoomConnectionParameters(String roomUrl, String roomId) {
            this.roomUrl = roomUrl;
            this.roomId = roomId;
        }
    }

    void connect();

    void doLogin(String userid, String passwd);

    void doLogin(String token);

    /**
     * 使用房间连接参数,发起异步连接。
     */
    void connectToRoom(RoomConnectionParameters connectionParameters);

    /**
     * 发送offer SDP给房间其他对话参与者。
     */
    void sendOfferSdp(final SessionDescription sdp);

    /**
     * 发送answer SDP给房间其他对话参与者。
     */
    void sendAnswerSdp(final SessionDescription sdp);

    /**
     * 发送Ice candidate给房间其他对话参与者。
     */
    void sendLocalIceCandidate(final IceCandidate candidate);

    /**
     * 发送removed ICE candidates给房间其他对话参与者。
     */
    void sendLocalIceCandidateRemovals(final IceCandidate[] candidates);

    /**
     * 关闭房间连接
     */
    void disconnectFromRoom();

    /**
     * 信令参数结构定义
     */
    class SignalingParameters {
        public final List<PeerConnection.IceServer> iceServers;
        public final boolean initiator;
        public final String clientId;
        public final String wssUrl;
        public final String wssPostUrl;
        public final SessionDescription offerSdp;
        public final List<IceCandidate> iceCandidates;

        public SignalingParameters(List<PeerConnection.IceServer> iceServers, boolean initiator,
                                   String clientId, String wssUrl, String wssPostUrl, SessionDescription offerSdp,
                                   List<IceCandidate> iceCandidates) {
            this.iceServers = iceServers;
            this.initiator = initiator;
            this.clientId = clientId;
            this.wssUrl = wssUrl;
            this.wssPostUrl = wssPostUrl;
            this.offerSdp = offerSdp;
            this.iceCandidates = iceCandidates;
        }
    }

    /**
     * 信令服务消息回调接口,在Activity UI线程调用
     */
    interface SignalingEvents {
        /**
         * Callback fired once the room's signaling parameters
         * SignalingParameters are extracted.
         */
        void onConnectedToRoom(final SignalingParameters params);

        /**
         * Callback fired once remote SDP is received.
         */
        void onRemoteDescription(final SessionDescription sdp);

        /**
         * Callback fired once remote Ice candidate is received.
         */
        void onRemoteIceCandidate(final IceCandidate candidate);

        /**
         * Callback fired once remote Ice candidate removals are received.
         */
        void onRemoteIceCandidatesRemoved(final IceCandidate[] candidates);

        /**
         * Callback fired once channel is closed.
         */
        void onChannelClose();

        /**
         * Callback fired once channel error happened.
         */
        void onChannelError(final String description);
    }
}
